#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <sstream>
#include <iostream>

#include "xgameengine.h"
using namespace std;

int main()
{
    XGameEngine game;

    if(!game.init(640, 480))
    {
        std::cerr << "Game Engine init failed!" << std::endl;
        return -1;
    }

    game.changeState(new XGameState());

    while(game.isRunning())
    {
        game.handleEvent();
        game.update();
        game.draw();
    }

    std::cout << "Game exits." << std::endl;
    game.cleanup();

    return 0;


    sf::RenderWindow window(sf::VideoMode(640, 480), "SFML Lesson");
    window.SetFramerateLimit(60);

    sf::Image image;
    //image.LoadFromFile("data/images/cb.bmp");

    sf::Font font;
    //font.LoadFromFile("data/fonts/WenQuanYiMicroHei.ttf");

    // Create a sprite
    sf::Sprite sprite;
    sprite.SetImage(image);

    sf::Text text;
    text.SetColor(sf::Color(123, 123,123,132));
    text.SetCharacterSize(12);
    text.SetFont(font);

    sf::RenderImage rimage;
    rimage.Create(600, 400);

    const sf::String title = L"SFML Test Demo - ";
    sf::Clock clock;

    std::string line = "确定";
    std::basic_string<sf::Uint32> u32line;
    sf::Utf8::ToUtf32(line.begin(), line.end(), std::back_inserter(u32line));
    text.SetString(u32line);
    text.SetPosition(400, 100);
    rimage.Clear(sf::Color::Blue);
    rimage.Draw(sf::Sprite(image));
    rimage.Draw(text);
    rimage.Display();

    // The main loop - ends as soon as the window is closed
    while (window.IsOpened())
    {
        // Event processing
        sf::Event event;
        while (window.PollEvent(event))
        {
            // Request for closing the window
            if (event.Type == sf::Event::Closed)
                window.Close();
        }

        // Clear the whole window before rendering a new frame

        window.Clear(sf::Color::White);
        sf::View v = window.GetView();

        // Draw some sprites / shapes / texts

        // End the current frame and display its contents on screen
        window.Display();
    }
    return 0;
}
